Add gtk_icon_paintable_get_icon_name()
authorAlexander Larsson <alexl@redhat.com>
Thu, 6 Feb 2020 16:28:19 +0000 (17:28 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 6 Feb 2020 16:47:57 +0000 (17:47 +0100)
This allows you to see which icon was actually chosen.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkicontheme.c
gtk/gtkicontheme.h
testsuite/gtk/icontheme.c

index fa4001a1f6b4e48e5503766d1c7deeb4119d8c3c..3316829a805eba50398d6e1a326d8eda78a7bc04 100644 (file)
@@ -5010,6 +5010,7 @@ gtk_icon_theme_lookup_by_gicon
 gtk_icon_theme_list_icons
 gtk_icon_theme_get_icon_sizes
 gtk_icon_paintable_get_filename
+gtk_icon_paintable_get_icon_name
 gtk_icon_paintable_is_symbolic
 <SUBSECTION Standard>
 GtkIconClass
index 2b94a87339e8069cc05e84202f3be3342489ddf2..65459be8e31bdebcad51b6a878af3cd38daa4c53 100644 (file)
@@ -261,6 +261,7 @@ struct _GtkIconPaintable
   IconKey key;
   GtkIconTheme *in_cache; /* Protected by icon_cache lock */
 
+  gchar *icon_name;
   gchar *filename;
   GLoadableIcon *loadable;
 
@@ -1909,6 +1910,7 @@ real_choose_icon (GtkIconTheme      *self,
   if (icon == NULL)
     {
       icon = icon_paintable_new (size, scale);
+      icon->icon_name = g_strdup ("image-missing");
       icon->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
       icon->is_resource = TRUE;
     }
@@ -2686,6 +2688,7 @@ theme_lookup_icon (IconTheme   *theme,
 
       filename = g_strconcat (icon_name, string_from_suffix (min_suffix), NULL);
       icon->filename = g_build_filename (dir->path, filename, NULL);
+      icon->icon_name = g_strdup (icon_name);
       icon->is_svg = min_suffix == ICON_CACHE_FLAG_SVG_SUFFIX;
       icon->is_resource = dir->is_resource;
       icon->is_symbolic = icon_uri_is_symbolic (filename, -1);
@@ -3092,6 +3095,7 @@ gtk_icon_paintable_finalize (GObject *object)
   g_strfreev (icon->key.icon_names);
 
   g_free (icon->filename);
+  g_free (icon->icon_name);
 
   g_clear_object (&icon->loadable);
   g_clear_object (&icon->texture);
@@ -3129,6 +3133,25 @@ gtk_icon_paintable_get_filename (GtkIconPaintable *icon)
   return icon->filename;
 }
 
+/**
+ * gtk_icon_paintable_get_icon_name:
+ * @self: a #GtkIcon
+ *
+ * Gets the icon name being used for the icon. This is only set
+ * if a themed icon was used, and will show the actual icon-name
+ * the was chosen.
+ *
+ * Returns: (nullable) (type filename): the themed icon-name for the icon, or %NULL
+ *     if its not a themed icon.
+ */
+const gchar *
+gtk_icon_paintable_get_icon_name (GtkIconPaintable *icon)
+{
+  g_return_val_if_fail (icon != NULL, NULL);
+
+  return icon->icon_name;
+}
+
 /**
  * gtk_icon_paintable_is_symbolic:
  * @self: a #GtkIcon
@@ -3282,6 +3305,7 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
   if (!source_pixbuf)
     {
       source_pixbuf = _gdk_pixbuf_new_from_resource (IMAGE_MISSING_RESOURCE_PATH, "png", NULL);
+      icon->icon_name = g_strdup ("image-missing");
       icon->is_symbolic = FALSE;
       g_assert (source_pixbuf != NULL);
     }
@@ -3579,6 +3603,7 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme       *self,
     {
       g_debug ("Unhandled GIcon type %s", g_type_name_from_instance ((GTypeInstance *)gicon));
       icon = icon_paintable_new (size, scale);
+      icon->icon_name = g_strdup ("image-missing");
       icon->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
       icon->is_resource = TRUE;
     }
index efacc13c500347d582aa6d6754b2ac75baa044bd..2a3366b7d5759d6a8713c066843270c22cc5d634 100644 (file)
@@ -139,6 +139,8 @@ GType                 gtk_icon_paintable_get_type         (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_ALL
 const gchar *         gtk_icon_paintable_get_filename     (GtkIconPaintable  *self);
 GDK_AVAILABLE_IN_ALL
+const gchar *         gtk_icon_paintable_get_icon_name    (GtkIconPaintable  *self);
+GDK_AVAILABLE_IN_ALL
 gboolean              gtk_icon_paintable_is_symbolic      (GtkIconPaintable  *self);
 
 G_END_DECLS
index 5c3b6cd008471200f547813973edcbad1bc9eb21..6d84adc5d803ee788f29d309d1a61572f4bda541 100644 (file)
@@ -121,7 +121,7 @@ assert_icon_lookup_fails (const char         *icon_name,
 
   /* We never truly *fail*, but check that we got the image-missing fallback */
   g_assert (info != NULL);
-  g_assert (g_str_has_suffix (gtk_icon_paintable_get_filename (info), "image-missing.png"));
+  g_assert_cmpstr (gtk_icon_paintable_get_icon_name (info), ==, "image-missing");
 }
 
 static GList *lookups = NULL;